package com.luaj.elasticsearch.service.impl;

import com.luaj.elasticsearch.mapper.UserMapper;
import com.luaj.elasticsearch.pojo.User;
import com.luaj.elasticsearch.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.weekend.WeekendSqls;

import javax.jws.soap.SOAPBinding;

/**
 * @author 卢安杰
 * @date 2020-11-20 20:06
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Override
    public int countAllUser() {
        return userMapper.selectCount(null);
    }

    @Override
    public User getUser(Integer id) {
        return userMapper.selectOne(new User(id));
    }

    @Override
    public User register(User registerUser) {
        int i = userMapper.insertSelective(registerUser);
        return getUser(registerUser.getId());
    }

    @Override
    public User login(String telphone, String password) {
        WeekendSqls<User> sqls=WeekendSqls.<User>custom();
        sqls.andEqualTo(User::getTelphone,telphone).andEqualTo(User::getPassword,password);
        return userMapper.selectOneByExample(Example.builder(User.class).where(sqls).build());

    }
}
